﻿using System;
using System.Collections.Generic;
using DinheiroSobControle.Dominio;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using Moq;

namespace DinheiroSobControle.Testes.Dominio
{
    /// <summary>
    /// Summary description for ExtratoTest
    /// </summary>
    [TestClass]
    public class ExtratoTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private Mock<DominioDataContext> _repositorio;

        [TestInitialize]
        public void InicializadorDeDados()
        {
            
            _repositorio = new Mock<DominioDataContext>("StringMock");
            
            var listaDeMovimentacoes = new List<MovimentacaoFinanceira>
                                           {
                                               new Recebimento(50) {Data = new DateTime(2009, 10, 10)},
                                               new Gasto(10) {Data = new DateTime(2009, 9, 10)},
                                               new Gasto(20) {Data = new DateTime(2009, 9, 11)}
                                           };
            _repositorio.Setup(repo => repo.GetQueryable<MovimentacaoFinanceira>()).
                Returns(listaDeMovimentacoes.AsQueryable).Verifiable();

            DominioDataContext.Instancia = _repositorio.Object;
        }

        [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TesteExtratoInvalidoIntervaloZerado()
        {
            Extrato.ObtenhaSaldo(DateTime.Now, DateTime.Now);
        }

        [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TesteExtratoInvalidoIntervaloNegativo()
        {
            Extrato.ObtenhaSaldo(new DateTime(2009, 10, 10), new DateTime(2009, 10, 9));
        }

        [TestMethod]
        public void TesteExtratoPeriodoTotal()
        {
            Assert.AreEqual(20m, Extrato.ObtenhaSaldo(new DateTime(2009,9,10), new DateTime(2009,10,10)),
                "O saldo para o periódo indicado deveria ser 20");
        }
    }
}
